home *** CD-ROM | disk | FTP | other *** search
- -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
- -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
- --
- class INTEGER_REF
-
- inherit
- NUMERIC
- redefine
- infix "+", infix "-", infix "*", infix "/",
- infix "^", prefix "-", prefix "+", valid_divisor,
- one, zero
- end;
- COMPARABLE
- redefine infix "<", compare, hash_code
- end;
-
- creation {ANY}
- make
-
- feature {ANY}
-
- item: INTEGER;
-
- make(value: INTEGER) is
- do
- item := value
- end;
-
- infix "+" (other: like Current): like Current is
- -- Add `other' to Current.
- do
- !!Result.make (item + other.item)
- end;
-
- infix "-" (other: like Current): like Current is
- -- Subtract `other' from Current.
- do
- !!Result.make (item - other.item)
- end;
-
- infix "*" (other: like Current): like Current is
- -- Multiply `other' by Current.
- do
- !!Result.make (item * other.item)
- end;
-
- infix "/" (other: like Current): DOUBLE_REF is
- -- Divide Current by `other'.
- -- Note: Integer division
- do
- !!Result.make (item / other.item)
- end;
-
- infix "//" (other: like Current): like Current is
- -- Divide Current by `other'.
- -- Note : Integer division
- require
- valid_divisor (other)
- do
- !!Result.make (item // other.item)
- end;
-
- infix "\\" (other: like Current): like Current is
- -- Remainder of division of Current by `other'.
- require
- valid_modulus: valid_divisor (other)
- do
- !!Result.make (item \\ other.item)
- end;
-
- infix "^" (exp: INTEGER): like Current is
- -- Raise Current to `exp'-th power.
- do
- !!Result.make (item ^ exp)
- end;
-
- infix "<" (other: like Current): BOOLEAN is
- -- Is Current less than `other'?
- do
- Result := (item < other.item)
- end;
-
- prefix "+": like Current is
- do
- !!Result.make (item)
- end;
-
- prefix "-": like Current is
- -- Unary minus of Current
- do
- !!Result.make (-item)
- end;
-
- compare (other: like Current): INTEGER is
- -- Compare Current with `other'.
- -- '<' <==> Result < 0
- -- '>' <==> Result > 0
- -- Otherwise Result = 0
- do
- Result := item - other.item
- end;
-
- hash_code: INTEGER is
- do
- if item < 0 then
- Result := -item
- else
- Result := item
- end;
- end;
-
- valid_divisor(other: like Current): BOOLEAN is
- do
- Result := (other.item /= 0)
- end;
-
- one: like Current is
- do
- !!Result.make (1)
- end;
-
- zero: like Current is
- do
- !!Result.make (0)
- end;
-
- end -- class INTEGER_REF
-